class Solution {
public:
    vector<vector<int>> res;
    vector<int> path;

    void dfs(TreeNode* root, vector<int> path,int targetSum)
    {
        if(!root) return;
        path.push_back(root->val);
        targetSum-=root->val;
        if(!root->left && !root->right && targetSum==0)
        {
            res.push_back(path);
        }
        dfs(root->left,path,targetSum);
        dfs(root->right,path,targetSum);
    }
    vector<vector<int>> pathSum(TreeNode* root, int targetSum) {
        if(!root) return res;
        dfs(root,path,targetSum);
        return res; 
    }
};

